package com.foxzzz.two.pointers;

public class Solution141 {
    class ListNode {
        int val;
        ListNode next;

        ListNode(int x) {
            val = x;
            next = null;
        }
    }

    public boolean hasCycle(ListNode head) {
        if (head == null)
            return false;
        ListNode slow = head;
        ListNode qucik = head;
        while (true) {
            slow = slow.next;
            qucik = qucik.next;
            if (qucik == null) {
                return false;
            }
            qucik = qucik.next;
            if (qucik == null) {
                return false;
            }
            if (slow == qucik) {
                return true;
            }
        }
    }

    public static void main(String[] args) {
        System.out.println(new Solution141().hasCycle(null));
    }
}
